package com.liddhome.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.liddhome.dao.BookDao;
import com.liddhome.entity.BookBean;
import com.liddhome.entity.PageBean;
import com.liddhome.util.PageBar;

/**
 * Servlet实现类FindServlet
 */
public class FindServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		int currPage = 1; // 当前页码
		if (request.getParameter("page") != null) { // 判断传递页码是否有效
			currPage = Integer.parseInt(request.getParameter("page"));// 对当前页码赋值
		}
		PageBean pb = new PageBean(currPage,2);
		BookDao dao = new BookDao(); // 实例化BookDao
		List<BookBean> list = dao.find(pb); // 查询所有图书信息
		request.setAttribute("list", list); // 将list放置到request中
		
		String sb = PageBar.pageBar(dao.findCount(), pb);
		request.setAttribute("bar", sb); // 将分页导航条的字符串放置到request中
		// 转发到bookList.jsp页面
		request.getRequestDispatcher("bookList.jsp").forward(request, response);

	}
}
